/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Negocio;

/**
 *
 * @author Estudiante
 */
public class Entero {
        public int num;
        public int getNum() {
            return num;
        }
        public void setNum(int num) {
            this.num = num;
        }    
        public Entero() {
            num = 0;
        }
        public Entero(int n) {
            num = n;
        }
        public int factorial() {
            int f = 1;
            for (int i = 1; i <= num; i++)
                f *= i;
            return f;
        }
        public boolean par(){
             return (num % 2 == 0); 
        }
        public int invertir(){
                num *=10;
                int aux=0;
                while ((num /= 10) > 0)
                    aux = (aux * 10) + (num % 10);
                return aux;            
        }
        public boolean capicua() {
            int aux=num;
            num=invertir();
            return aux == num;
        }
        public int count() {
            int c = 0;
            num *= 10;
            while ((num /= 10) > 0)
                c++;
            return c;
        }
        public int cantidad_primos() {            
                int c = 0; num *= 10;
                while ((num /= 10) > 0)
                    if (primo(num % 10))
                        c++;
                return c;            
        }
        public boolean primo(int n) {
            for (int i = 2; i < n; i++)
                if (n % i == 0)
                    return false;
            return true;
        }
        public int catidad_par()  {
                int c = 0,aux=num;
                num *= 10;
                while ((num /= 10) > 0)
                    if ((num % 10) % 2 == 0)
                        c++;
                setNum(aux);
                return c;            
        }
        public int catidad_impar()    {
                int c = 0, aux = num;
                num *= 10;
                while ((num /= 10) > 0)
                    if ((num % 10) % 2 != 0)
                        c++;
                setNum(aux);
                return c;            
        }
        public int digitos_primos()   {
                num *= 10;
                int aux = 0;
                while ((num /= 10) > 0)
                    if (primo(num % 10))
                        aux = (aux * 10) + (num % 10);
                setNum(aux);
                num = invertir();
                return num;
        }
        public double promedio_pares() {
                int aux = num,suma=0,c=0;
                num *= 10;
                while ((num /= 10) > 0)
                    if ((num % 10) % 2 == 0){
                        suma += (num % 10);
                        c++;
                    }
                setNum(aux);
                return suma/c;
        }
        /*
         * Hay que desarrollar las funciones para ordenar los digitos de un numero de menor a mayor
         * y de mayor a menor... y tambien mostrar un numero en su forma literal
         */
        public String fibonacci() {
            String cad = "";
            int a = 1, b, c;
            b = c = 0;
            for (int i = 0; i < num; i++) {
                b = a;
                a = b + c;
                c = b;
                cad += String.valueOf(a) + "   ";
            }
            return cad;
        }
}
